Import mojo
Import agfx


Class TTiled_Tileset
	
	Public

	Field firstgid:Int
	Field name:String
	
	Field tilewidth:Int
	Field tileheight:Int
	Field image:TTiled_TilesetImage
	Field tiles:ArrayList<TTiled_TilesetTile> = New ArrayList<TTiled_TilesetTile>

	'------------------------------------------------------------------------------------
	'
	'------------------------------------------------------------------------------------

	Method New(node:XMLElement)
	
	
		If DEBUG Then Print("<TILESET>")
		If DEBUG Then Print("  Load from - TILESET node ")
		Self.name 		= node.GetAttribute("name")
		If DEBUG Then Print("  name: "+Self.name)
				
		Self.firstgid 	= Int(node.GetAttribute("firstgid"))
		If DEBUG Then Print("  firstgid: "+Self.firstgid)
		
		Self.tilewidth 	= Int(node.GetAttribute("tilewidth"))
		If DEBUG Then Print("  tilewidth: "+Self.tilewidth)
		
		Self.tileheight = Int(node.GetAttribute("tileheight"))
		If DEBUG Then Print("  tileheight: "+Self.tileheight)
		
		Local tileset:XMLElement
		
		For tileset = EachIn node.Children
			
			Select tileset.Name()
			
			
			
				Case "image"
			
					Self.image = New TTiled_TilesetImage(tileset)
			
				Case "tile"
					
					Local t:TTiled_TilesetTile = New TTiled_TilesetTile(tileset)
					Self.tiles.Add(t)
			
			End Select
		
		Next
	
	End Method
	
	
	'------------------------------------------------------------------------------------
	'
	'------------------------------------------------------------------------------------

	Method New(node:XMLElement,node_src:XMLElement)
	
		
		If DEBUG Then Print("<TILESET>")
		If DEBUG Then Print("  Load from tsx file - external TILESET")
		Self.name 		= node_src.GetAttribute("name")
		If DEBUG Then Print("  name: "+Self.name)
				
		Self.firstgid 	= Int(node.GetAttribute("firstgid"))
		If DEBUG Then Print("  firstgid: "+Self.firstgid)
		
		Self.tilewidth 	= Int(node_src.GetAttribute("tilewidth"))
		If DEBUG Then Print("  tilewidth: "+Self.tilewidth)
		
		Self.tileheight = Int(node_src.GetAttribute("tileheight"))
		If DEBUG Then Print("  tileheight: "+Self.tileheight)
		
		Local tileset:XMLElement
		
		For tileset = EachIn node_src.Children
			
			Select tileset.Name()
			
			
			
				Case "image"
			
					Self.image = New TTiled_TilesetImage(tileset)
			
				Case "tile"
					
					Local t:TTiled_TilesetTile = New TTiled_TilesetTile(tileset)
					Self.tiles.Add(t)
			
			End Select
		
		Next
	
	End Method
	
	'------------------------------------------------------------------------------------
	' Prepare
	'------------------------------------------------------------------------------------
	Method Prepare:Void()
		Self.image.Load(Self.tilewidth,Self.tileheight)
	End method

	
	
End Class